import sys
base = ['tret','jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jly', 'aug', 'sep', 'oct', 'nov', 'dec']
higher = ['tret','tam', 'hel', 'maa', 'huh', 'tou', 'kes', 'hei', 'elo', 'syy', 'lok', 'mer', 'jou']
def translate(number):
	numbers = number.split()
	if len(numbers) == 1 and  base.count(numbers[0]) == 0 and higher.count(numbers[0]) == 0:
		_base = int(numbers[0]) % 13
		_higher = int(numbers[0]) / 13
		print higher[_higher] + ' ' + base[_base]
	elif len(numbers) == 1 :
		if base.count(numbers[0]) >0 :
			print base.index(numbers[0])
		else:
			print higher.index(numbers[0]) * 13
	else:
		_base = base.index(numbers[1])
		_higher = higher.index(numbers[0])
		print _higher * 13 + _base
	pass

n = input()
for i in range(n):
	number = input()
	translate(str(numbers)